home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: Am I imagining auto_ptr?
- Message-ID: <marnoldDMwwrJ.5Bn@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <3124A4D5.FF@novell.com>
- Date: Sat, 17 Feb 1996 08:54:55 GMT
- Sender: marnold@netcom.netcom.com
-
- Jeff Robison <jeffr@novell.com> writes:
-
- >It seems like I recently read or heard or dreamed about a new keyword/type/whatever
- >in the C++ draft standard called an auto_ptr. I believe it will automatically
- >delete its contents when it goes out of scope. Something like this would be
- >incredibly useful when handling (or rather not having to handle) exceptions.
-
- >Am I imagining things, or does such a beast exist? If it does exist, can you point
- >me to some syntax/usage documentation?
-
- It's nothing more than a template class. It's not a special keyword or
- anything---you could easily create such a template yourself. Many C++
- books on the market have covered the "automatic pointer" concept in one
- form or another. And, yes, the auto_ptr template class is part of the
- C++ standard library.
-
- Here's the *basic* idea...
-
- // this IS NOT the real auto_ptr class, it is only a simple
- // illustration
-
- template <class T>
- class auto_ptr
- {
- public:
- auto_ptr(T* pt): m_pt(pt)
- { }
-
- ~auto_ptr()
- { delete m_pt; }
-
- T* operator->()
- { return m_pt; }
-
- private:
- T* m_pt;
- };
-
-
- Off the top of my head, I know that Scott Meyer's latest book "More
- Effective C++" lists the source code to the auto_ptr template class from
- the standard library. It's not very complicated. It's certainly not a
- "beast".
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-